package com.xmzs.midjourney.controller;

import java.util.List;

import com.xmzs.midjourney.domain.MjRoomMsg;
import com.xmzs.midjourney.domain.request.MjConvertRequest;
import com.xmzs.midjourney.domain.request.MjDescribeRequest;
import com.xmzs.midjourney.domain.request.MjImagineRequest;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

import com.xmzs.common.web.core.BaseController;
import com.xmzs.common.mybatis.core.page.PageQuery;
import com.xmzs.common.core.domain.R;
import com.xmzs.common.core.validate.AddGroup;
import com.xmzs.common.core.validate.EditGroup;
import com.xmzs.common.log.enums.BusinessType;

import com.xmzs.midjourney.domain.vo.MjRoomMsgVo;
import com.xmzs.midjourney.domain.bo.MjRoomMsgBo;
import com.xmzs.midjourney.service.IMjRoomMsgService;
import com.xmzs.common.mybatis.core.page.TableDataInfo;
import lombok.extern.slf4j.Slf4j;
/**
 * Midjourney 创作记录
 *
 * @author lixg
 * @date 2023-08-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/midjourney/mjRoomMsg")
public class MjRoomMsgController extends BaseController {

    private final IMjRoomMsgService mjRoomMsgService;

    /**
     * 查询Midjourney 创作记录列表
     */
    @SaCheckPermission("midjourney:mjRoomMsg:list")
    @GetMapping("/list")
    public TableDataInfo<MjRoomMsgVo> list(MjRoomMsgBo bo, PageQuery pageQuery) {
        return mjRoomMsgService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取Midjourney 创作记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("midjourney:mjRoomMsg:query")
    @GetMapping("/{id}")
    public R<MjRoomMsg> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(mjRoomMsgService.queryById(id));
    }

    /**
     * 新增Midjourney 创作记录
     */
    @SaCheckPermission("midjourney:mjRoomMsg:add")
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MjRoomMsgBo bo) {
        return toAjax(mjRoomMsgService.insertByBo(bo));
    }

    /**
     * 修改Midjourney 创作记录
     */
    @SaCheckPermission("midjourney:mjRoomMsg:edit")
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MjRoomMsgBo bo) {
        return toAjax(mjRoomMsgService.updateByBo(bo));
    }

    /**
     * 删除Midjourney 创作记录
     *
     * @param ids 主键串
     */
    @SaCheckPermission("midjourney:mjRoomMsg:remove")
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(mjRoomMsgService.deleteWithValidByIds(List.of(ids), true));
    }


    @Operation(summary = "imagine")
    @PostMapping("/imagine")
    public R<Boolean> imagine(@Validated @RequestBody MjImagineRequest imagineRequest) {
        mjRoomMsgService.imagine(imagineRequest);
        return R.data(true);
    }


    @Operation(summary = "upscale")
    @PostMapping("/upscale")
    public R<Boolean> upscale(@Validated @RequestBody MjConvertRequest convertRequest) {
        mjRoomMsgService.upscale(convertRequest);
        return R.data(true);
    }

    @Operation(summary = "variation")
    @PostMapping("/variation")
    public R<Boolean> variation(@Validated @RequestBody MjConvertRequest convertRequest) {
        mjRoomMsgService.variation(convertRequest);
        return R.data(true);
    }

    @Operation(summary = "describe")
    @PostMapping("/describe")
    public R<Boolean> describe(@Validated @ModelAttribute MjDescribeRequest describeRequest) {
        mjRoomMsgService.describe(describeRequest);
        return R.data(true);
    }
}
